package com.restaurant.application.indexes.couponlist.mysql;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.nebutown.base.Unit;
import com.nebutown.description.data.SortSpec;
import com.nebutown.generation.basictype.UID;
import com.nebutown.supporthome.AbstractIndex;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

public class CouponListImpl extends AbstractIndex<CouponListCriteria, CouponListBean> {

    @Override
    public String getTableName() {
        return "" + getConnectionName() + ".COUPONLIST";
    }

    @Override
    public CouponListBean newBean() {
        return new CouponListBean();
    }

    @Override
    public CouponListCriteria newCriteria() {
        return new CouponListCriteria();
    }

    @Override
    public List<String> getFieldNames() {
        return Lists.newArrayList(
                "couponUid",
                "couponManageUid",
                "number",
                "endTime",
                "type",
                "modality",
                "fullMoney",
                "minusMoney",
                "shopUid",
                "shopName",
                "remarks",
                "state",
                "id",
                "createTime",
                "modifyTime",
                "customerId",
                "customerUid",
                "customerName",
                "phone",
                "qrCodeUrl",
                "qrCodeUid",
                "couponState",
                "currentCustomerId",
                "currentCustomerUid",
                "currentCustomerName",
                "currentPhone",
                "usedCustomerId",
                "usedCustomerUid",
                "usedCustomerName",
                "usedPhone",
                "usedTime",
                "userId",
                "userUid",
                "userName");
    }

    @Override
    public List<String> getDateFields() {
        return Lists.newArrayList(
                "endTime",
                "createTime",
                "modifyTime",
                "usedTime");
    }

    @Override
    public List<String> getDoubleFields() {
        return Lists.newArrayList(
                "fullMoney",
                "minusMoney");
    }

    @Override
    public Map<String, String> getFieldLabels() {
        return ImmutableMap.<String, String>builder()
                .put("couponManageUid", "优惠券管理uid")
                .put("number", "优惠券编号")
                .put("endTime", "服务期限时间")
                .put("type", "优惠券类型")
                .put("modality", "优惠券形式")
                .put("fullMoney", "满多少金额")
                .put("minusMoney", "减多少金额")
                .put("shopUid", "店铺Uid")
                .put("shopName", "店铺名称")
                .put("remarks", "备注（注意事项）")
                .put("state", "是否过期")
                .put("id", "优惠券id")
                .put("createTime", "创建时间")
                .put("modifyTime", "修改时间")
                .put("customerId", "领券客户Id")
                .put("customerUid", "领券客户Uid")
                .put("customerName", "领券客户名称")
                .put("phone", "领券联系方式")
                .put("qrCodeUrl", "二维码地址")
                .put("qrCodeUid", "二维码Uid")
                .put("couponState", "是否使用")
                .put("currentCustomerId", "当前客户Id")
                .put("currentCustomerUid", "当前客户Uid")
                .put("currentCustomerName", "当前客户名称")
                .put("currentPhone", "当前联系方式")
                .put("usedCustomerId", "当前客户Id")
                .put("usedCustomerUid", "当前客户Uid")
                .put("usedCustomerName", "当前客户名称")
                .put("usedPhone", "当前联系方式")
                .put("usedTime", "使用时间")
                .put("userId", "客户Id")
                .put("userUid", "客户Uid")
                .put("userName", "客户名称")
                .build();
    }

    @Override
    public List<String> getContributors() {
        return Lists.newArrayList(
                "com.restaurant.application.coupon.Coupon");
    }

    @Override
    public CouponListBean fakeBean() {
        CouponListBean bean = new CouponListBean();

        bean.setCouponUid(UID.recover("A -1031281759665041824 looooong string"));
        bean.setCouponManageUid("A -2449954870085882707 looooong string");
        bean.setNumber("A 385582166106607488 looooong string");
        bean.setEndTime(1984861964L);
        bean.setType("A 5251755699875620475 looooong string");
        bean.setModality("A 3870549762152762319 looooong string");
        bean.setFullMoney(0.7193797384275529);
        bean.setMinusMoney(0.41048075759644176);
        bean.setShopUid("A -2369431142825750008 looooong string");
        bean.setShopName("A 5784486635661053412 looooong string");
        bean.setRemarks("A -7137806943607171103 looooong string");
        bean.setState("A -3331535452634106765 looooong string");
        bean.setId("A -8046579921475357161 looooong string");
        bean.setCreateTime(-1958279629L);
        bean.setModifyTime(-506816008L);
        bean.setCustomerId("A 8321608476399409443 looooong string");
        bean.setCustomerUid("A 4592069666670161567 looooong string");
        bean.setCustomerName("A -2991256161530459928 looooong string");
        bean.setPhone("A -1804405945988601236 looooong string");
        bean.setQrCodeUrl("A 2187706606546598603 looooong string");
        bean.setQrCodeUid("A -2123649823317521224 looooong string");
        bean.setCouponState("A 4941027338904416406 looooong string");
        bean.setCurrentCustomerId("A -2622316339792948056 looooong string");
        bean.setCurrentCustomerUid("A -596815414657926918 looooong string");
        bean.setCurrentCustomerName("A -4643342213398174013 looooong string");
        bean.setCurrentPhone("A 2173796485052498958 looooong string");
        bean.setUsedCustomerId("A -3912954381661970607 looooong string");
        bean.setUsedCustomerUid("A -8898336033358143828 looooong string");
        bean.setUsedCustomerName("A -6484756563898734627 looooong string");
        bean.setUsedPhone("A -2917036297784575576 looooong string");
        bean.setUsedTime(556630541L);
        bean.setUserId("A 1008398167415755402 looooong string");
        bean.setUserUid("A -8171685698471504682 looooong string");
        bean.setUserName("A -3715190846848651764 looooong string");
        return bean;
    }

    @Override
    public String getCreateTableStatement() {
        StringBuilder buf = new StringBuilder();

        buf.append("CREATE TABLE IF NOT EXISTS " + getConnectionName() + ".COUPONLIST (\n");
        buf.append("    RECORD_ID BIGINT AUTO_INCREMENT,\n");
        buf.append("    COUPONUID CHAR(128) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,\n");
        buf.append("    COUPONMANAGEUID VARCHAR(255),\n");
        buf.append("    NUMBER VARCHAR(255),\n");
        buf.append("    ENDTIME BIGINT,\n");
        buf.append("    TYPE VARCHAR(255),\n");
        buf.append("    MODALITY VARCHAR(255),\n");
        buf.append("    FULLMONEY REAL,\n");
        buf.append("    MINUSMONEY REAL,\n");
        buf.append("    SHOPUID VARCHAR(255),\n");
        buf.append("    SHOPNAME VARCHAR(255),\n");
        buf.append("    REMARKS VARCHAR(255),\n");
        buf.append("    STATE VARCHAR(255),\n");
        buf.append("    ID VARCHAR(255),\n");
        buf.append("    CREATETIME BIGINT,\n");
        buf.append("    MODIFYTIME BIGINT,\n");
        buf.append("    CUSTOMERID VARCHAR(255),\n");
        buf.append("    CUSTOMERUID VARCHAR(255),\n");
        buf.append("    CUSTOMERNAME VARCHAR(255),\n");
        buf.append("    PHONE VARCHAR(255),\n");
        buf.append("    QRCODEURL VARCHAR(255),\n");
        buf.append("    QRCODEUID VARCHAR(255),\n");
        buf.append("    COUPONSTATE VARCHAR(255),\n");
        buf.append("    CURRENTCUSTOMERID VARCHAR(255),\n");
        buf.append("    CURRENTCUSTOMERUID VARCHAR(255),\n");
        buf.append("    CURRENTCUSTOMERNAME VARCHAR(255),\n");
        buf.append("    CURRENTPHONE VARCHAR(255),\n");
        buf.append("    USEDCUSTOMERID VARCHAR(255),\n");
        buf.append("    USEDCUSTOMERUID VARCHAR(255),\n");
        buf.append("    USEDCUSTOMERNAME VARCHAR(255),\n");
        buf.append("    USEDPHONE VARCHAR(255),\n");
        buf.append("    USEDTIME BIGINT,\n");
        buf.append("    USERID VARCHAR(255),\n");
        buf.append("    USERUID VARCHAR(255),\n");
        buf.append("    USERNAME VARCHAR(255),\n");
        buf.append("PRIMARY KEY (RECORD_ID)) CHARACTER SET  = utf8mb4 COLLATE = utf8mb4_bin");
        return buf.toString();
    }

    @Override
    public String getInsertDataStatement(CouponListBean data) {
        StringBuilder buf = new StringBuilder();

        buf.append("INSERT INTO " + getConnectionName() + ".COUPONLIST (\n    ");
        buf.append("    COUPONUID, COUPONMANAGEUID, NUMBER, ENDTIME, TYPE, MODALITY, FULLMONEY, MINUSMONEY, SHOPUID, SHOPNAME, REMARKS, STATE, ID, CREATETIME, MODIFYTIME, CUSTOMERID, CUSTOMERUID, CUSTOMERNAME, PHONE, QRCODEURL, QRCODEUID, COUPONSTATE, CURRENTCUSTOMERID, CURRENTCUSTOMERUID, CURRENTCUSTOMERNAME, CURRENTPHONE, USEDCUSTOMERID, USEDCUSTOMERUID, USEDCUSTOMERNAME, USEDPHONE, USEDTIME, USERID, USERUID, USERNAME");
        buf.append(") VALUES (");
        buf.append("    '" + cut(data.getCouponUid(), 128) + "', '" + cut(data.getCouponManageUid(), 255) + "', '" + cut(data.getNumber(), 255) + "', " + data.getEndTime() + ", '" + cut(data.getType(), 255) + "', '" + cut(data.getModality(), 255) + "', " + data.getFullMoney() + ", " + data.getMinusMoney() + ", '" + cut(data.getShopUid(), 255) + "', '" + cut(data.getShopName(), 255) + "', '" + cut(data.getRemarks(), 255) + "', '" + cut(data.getState(), 255) + "', '" + cut(data.getId(), 255) + "', " + data.getCreateTime() + ", " + data.getModifyTime() + ", '" + cut(data.getCustomerId(), 255) + "', '" + cut(data.getCustomerUid(), 255) + "', '" + cut(data.getCustomerName(), 255) + "', '" + cut(data.getPhone(), 255) + "', '" + cut(data.getQrCodeUrl(), 255) + "', '" + cut(data.getQrCodeUid(), 255) + "', '" + cut(data.getCouponState(), 255) + "', '" + cut(data.getCurrentCustomerId(), 255) + "', '" + cut(data.getCurrentCustomerUid(), 255) + "', '" + cut(data.getCurrentCustomerName(), 255) + "', '" + cut(data.getCurrentPhone(), 255) + "', '" + cut(data.getUsedCustomerId(), 255) + "', '" + cut(data.getUsedCustomerUid(), 255) + "', '" + cut(data.getUsedCustomerName(), 255) + "', '" + cut(data.getUsedPhone(), 255) + "', " + data.getUsedTime() + ", '" + cut(data.getUserId(), 255) + "', '" + cut(data.getUserUid(), 255) + "', '" + cut(data.getUserName(), 255) + "'");
        buf.append(")");
        return buf.toString();
    }

    @Override
    public String getDeleteRowsStatement(Long rowId) {
        return "DELETE FROM " + getConnectionName() + ".COUPONLIST WHERE  RECORD_ID = " + rowId;
    }

    @Override
    public String getLocalUpdateStatement(CouponListBean data) {
        StringBuilder buf = new StringBuilder();
        StringBuilder sep = new StringBuilder();

        boolean hasData = false;

        buf.append("UPDATE " + getConnectionName() + ".COUPONLIST \n");
        buf.append("   SET ");
        if(data.getCouponUid() != null) {
            buf.append(sep.toString() + "\n      COUPONUID = '" + cut(data.getCouponUid(), 128) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCouponManageUid() != null) {
            buf.append(sep.toString() + "\n      COUPONMANAGEUID = '" + cut(data.getCouponManageUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getNumber() != null) {
            buf.append(sep.toString() + "\n      NUMBER = '" + cut(data.getNumber(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getEndTime() != null) {
            buf.append(sep.toString() + "\n      ENDTIME = " + data.getEndTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getType() != null) {
            buf.append(sep.toString() + "\n      TYPE = '" + cut(data.getType(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModality() != null) {
            buf.append(sep.toString() + "\n      MODALITY = '" + cut(data.getModality(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getFullMoney() != null) {
            buf.append(sep.toString() + "\n      FULLMONEY = " + data.getFullMoney() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getMinusMoney() != null) {
            buf.append(sep.toString() + "\n      MINUSMONEY = " + data.getMinusMoney() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopUid() != null) {
            buf.append(sep.toString() + "\n      SHOPUID = '" + cut(data.getShopUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopName() != null) {
            buf.append(sep.toString() + "\n      SHOPNAME = '" + cut(data.getShopName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getRemarks() != null) {
            buf.append(sep.toString() + "\n      REMARKS = '" + cut(data.getRemarks(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getState() != null) {
            buf.append(sep.toString() + "\n      STATE = '" + cut(data.getState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getId() != null) {
            buf.append(sep.toString() + "\n      ID = '" + cut(data.getId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCreateTime() != null) {
            buf.append(sep.toString() + "\n      CREATETIME = " + data.getCreateTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getModifyTime() != null) {
            buf.append(sep.toString() + "\n      MODIFYTIME = " + data.getModifyTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerId() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERID = '" + cut(data.getCustomerId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerUid() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERUID = '" + cut(data.getCustomerUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerName() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERNAME = '" + cut(data.getCustomerName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getPhone() != null) {
            buf.append(sep.toString() + "\n      PHONE = '" + cut(data.getPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getQrCodeUrl() != null) {
            buf.append(sep.toString() + "\n      QRCODEURL = '" + cut(data.getQrCodeUrl(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getQrCodeUid() != null) {
            buf.append(sep.toString() + "\n      QRCODEUID = '" + cut(data.getQrCodeUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCouponState() != null) {
            buf.append(sep.toString() + "\n      COUPONSTATE = '" + cut(data.getCouponState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCurrentCustomerId() != null) {
            buf.append(sep.toString() + "\n      CURRENTCUSTOMERID = '" + cut(data.getCurrentCustomerId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCurrentCustomerUid() != null) {
            buf.append(sep.toString() + "\n      CURRENTCUSTOMERUID = '" + cut(data.getCurrentCustomerUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCurrentCustomerName() != null) {
            buf.append(sep.toString() + "\n      CURRENTCUSTOMERNAME = '" + cut(data.getCurrentCustomerName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCurrentPhone() != null) {
            buf.append(sep.toString() + "\n      CURRENTPHONE = '" + cut(data.getCurrentPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUsedCustomerId() != null) {
            buf.append(sep.toString() + "\n      USEDCUSTOMERID = '" + cut(data.getUsedCustomerId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUsedCustomerUid() != null) {
            buf.append(sep.toString() + "\n      USEDCUSTOMERUID = '" + cut(data.getUsedCustomerUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUsedCustomerName() != null) {
            buf.append(sep.toString() + "\n      USEDCUSTOMERNAME = '" + cut(data.getUsedCustomerName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUsedPhone() != null) {
            buf.append(sep.toString() + "\n      USEDPHONE = '" + cut(data.getUsedPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getUsedTime() != null) {
            buf.append(sep.toString() + "\n      USEDTIME = " + data.getUsedTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUserId() != null) {
            buf.append(sep.toString() + "\n      USERID = '" + cut(data.getUserId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUserUid() != null) {
            buf.append(sep.toString() + "\n      USERUID = '" + cut(data.getUserUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUserName() != null) {
            buf.append(sep.toString() + "\n      USERNAME = '" + cut(data.getUserName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(!hasData) return "";

        hasData = false;
        buf.append(" WHERE TRUE\n");
        if(data.getCouponUid() != null) {
            buf.append("    AND COUPONUID = '" + data.getCouponUid() + "'\n");
            hasData = true;
        }
        if(!hasData) return "";

        return buf.toString();
    }

    @Override
    public String getUpdateByIdStatement(CouponListBean data) {
        StringBuilder buf = new StringBuilder();
        StringBuilder sep = new StringBuilder();

        boolean hasData = false;

        buf.append("UPDATE " + getConnectionName() + ".COUPONLIST \n");
        buf.append("   SET ");
        if(data.getCouponUid() != null) {
            buf.append(sep.toString() + "\n      COUPONUID = '" + cut(data.getCouponUid(), 128) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCouponManageUid() != null) {
            buf.append(sep.toString() + "\n      COUPONMANAGEUID = '" + cut(data.getCouponManageUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getNumber() != null) {
            buf.append(sep.toString() + "\n      NUMBER = '" + cut(data.getNumber(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getEndTime() != null) {
            buf.append(sep.toString() + "\n      ENDTIME = " + data.getEndTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getType() != null) {
            buf.append(sep.toString() + "\n      TYPE = '" + cut(data.getType(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModality() != null) {
            buf.append(sep.toString() + "\n      MODALITY = '" + cut(data.getModality(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getFullMoney() != null) {
            buf.append(sep.toString() + "\n      FULLMONEY = " + data.getFullMoney() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getMinusMoney() != null) {
            buf.append(sep.toString() + "\n      MINUSMONEY = " + data.getMinusMoney() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopUid() != null) {
            buf.append(sep.toString() + "\n      SHOPUID = '" + cut(data.getShopUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopName() != null) {
            buf.append(sep.toString() + "\n      SHOPNAME = '" + cut(data.getShopName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getRemarks() != null) {
            buf.append(sep.toString() + "\n      REMARKS = '" + cut(data.getRemarks(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getState() != null) {
            buf.append(sep.toString() + "\n      STATE = '" + cut(data.getState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getId() != null) {
            buf.append(sep.toString() + "\n      ID = '" + cut(data.getId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCreateTime() != null) {
            buf.append(sep.toString() + "\n      CREATETIME = " + data.getCreateTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getModifyTime() != null) {
            buf.append(sep.toString() + "\n      MODIFYTIME = " + data.getModifyTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerId() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERID = '" + cut(data.getCustomerId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerUid() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERUID = '" + cut(data.getCustomerUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerName() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERNAME = '" + cut(data.getCustomerName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getPhone() != null) {
            buf.append(sep.toString() + "\n      PHONE = '" + cut(data.getPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getQrCodeUrl() != null) {
            buf.append(sep.toString() + "\n      QRCODEURL = '" + cut(data.getQrCodeUrl(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getQrCodeUid() != null) {
            buf.append(sep.toString() + "\n      QRCODEUID = '" + cut(data.getQrCodeUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCouponState() != null) {
            buf.append(sep.toString() + "\n      COUPONSTATE = '" + cut(data.getCouponState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCurrentCustomerId() != null) {
            buf.append(sep.toString() + "\n      CURRENTCUSTOMERID = '" + cut(data.getCurrentCustomerId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCurrentCustomerUid() != null) {
            buf.append(sep.toString() + "\n      CURRENTCUSTOMERUID = '" + cut(data.getCurrentCustomerUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCurrentCustomerName() != null) {
            buf.append(sep.toString() + "\n      CURRENTCUSTOMERNAME = '" + cut(data.getCurrentCustomerName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getCurrentPhone() != null) {
            buf.append(sep.toString() + "\n      CURRENTPHONE = '" + cut(data.getCurrentPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUsedCustomerId() != null) {
            buf.append(sep.toString() + "\n      USEDCUSTOMERID = '" + cut(data.getUsedCustomerId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUsedCustomerUid() != null) {
            buf.append(sep.toString() + "\n      USEDCUSTOMERUID = '" + cut(data.getUsedCustomerUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUsedCustomerName() != null) {
            buf.append(sep.toString() + "\n      USEDCUSTOMERNAME = '" + cut(data.getUsedCustomerName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUsedPhone() != null) {
            buf.append(sep.toString() + "\n      USEDPHONE = '" + cut(data.getUsedPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getUsedTime() != null) {
            buf.append(sep.toString() + "\n      USEDTIME = " + data.getUsedTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUserId() != null) {
            buf.append(sep.toString() + "\n      USERID = '" + cut(data.getUserId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUserUid() != null) {
            buf.append(sep.toString() + "\n      USERUID = '" + cut(data.getUserUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getUserName() != null) {
            buf.append(sep.toString() + "\n      USERNAME = '" + cut(data.getUserName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(!hasData) return "";

        hasData = false;
        buf.append(" WHERE RECORD_ID = " + data.getRecordId());
        return buf.toString();
    }

    @Override
    public CouponListBean extractLine(ResultSet resultSet) throws Exception {
        CouponListBean result = new CouponListBean();

        result.setRecordId(resultSet.getLong("RECORD_ID"));
        result.setCouponUid(UID.recover(resultSet.getString("couponUid")));
        result.setCouponManageUid(resultSet.getString("couponManageUid"));
        result.setNumber(resultSet.getString("number"));
        result.setEndTime(resultSet.getLong("endTime"));
        result.setType(resultSet.getString("type"));
        result.setModality(resultSet.getString("modality"));
        result.setFullMoney(resultSet.getDouble("fullMoney"));
        result.setMinusMoney(resultSet.getDouble("minusMoney"));
        result.setShopUid(resultSet.getString("shopUid"));
        result.setShopName(resultSet.getString("shopName"));
        result.setRemarks(resultSet.getString("remarks"));
        result.setState(resultSet.getString("state"));
        result.setId(resultSet.getString("id"));
        result.setCreateTime(resultSet.getLong("createTime"));
        result.setModifyTime(resultSet.getLong("modifyTime"));
        result.setCustomerId(resultSet.getString("customerId"));
        result.setCustomerUid(resultSet.getString("customerUid"));
        result.setCustomerName(resultSet.getString("customerName"));
        result.setPhone(resultSet.getString("phone"));
        result.setQrCodeUrl(resultSet.getString("qrCodeUrl"));
        result.setQrCodeUid(resultSet.getString("qrCodeUid"));
        result.setCouponState(resultSet.getString("couponState"));
        result.setCurrentCustomerId(resultSet.getString("currentCustomerId"));
        result.setCurrentCustomerUid(resultSet.getString("currentCustomerUid"));
        result.setCurrentCustomerName(resultSet.getString("currentCustomerName"));
        result.setCurrentPhone(resultSet.getString("currentPhone"));
        result.setUsedCustomerId(resultSet.getString("usedCustomerId"));
        result.setUsedCustomerUid(resultSet.getString("usedCustomerUid"));
        result.setUsedCustomerName(resultSet.getString("usedCustomerName"));
        result.setUsedPhone(resultSet.getString("usedPhone"));
        result.setUsedTime(resultSet.getLong("usedTime"));
        result.setUserId(resultSet.getString("userId"));
        result.setUserUid(resultSet.getString("userUid"));
        result.setUserName(resultSet.getString("userName"));
        return result;
    }

    @Override
    public String getWherePart(CouponListCriteria criteria, SortSpec sort) {
        StringBuilder buf = new StringBuilder(" TRUE ");

        criteria.setCouponManageUidLike(searchString(criteria.getCouponManageUidLike()));
        criteria.setNumberLike(searchString(criteria.getNumberLike()));
        criteria.setTypeLike(searchString(criteria.getTypeLike()));
        criteria.setModalityLike(searchString(criteria.getModalityLike()));
        criteria.setShopUidLike(searchString(criteria.getShopUidLike()));
        criteria.setShopNameLike(searchString(criteria.getShopNameLike()));
        criteria.setRemarksLike(searchString(criteria.getRemarksLike()));
        criteria.setStateLike(searchString(criteria.getStateLike()));
        criteria.setIdLike(searchString(criteria.getIdLike()));
        criteria.setCustomerIdLike(searchString(criteria.getCustomerIdLike()));
        criteria.setCustomerUidLike(searchString(criteria.getCustomerUidLike()));
        criteria.setCustomerNameLike(searchString(criteria.getCustomerNameLike()));
        criteria.setPhoneLike(searchString(criteria.getPhoneLike()));
        criteria.setQrCodeUrlLike(searchString(criteria.getQrCodeUrlLike()));
        criteria.setQrCodeUidLike(searchString(criteria.getQrCodeUidLike()));
        criteria.setCouponStateLike(searchString(criteria.getCouponStateLike()));
        criteria.setCurrentCustomerIdLike(searchString(criteria.getCurrentCustomerIdLike()));
        criteria.setCurrentCustomerUidLike(searchString(criteria.getCurrentCustomerUidLike()));
        criteria.setCurrentCustomerNameLike(searchString(criteria.getCurrentCustomerNameLike()));
        criteria.setCurrentPhoneLike(searchString(criteria.getCurrentPhoneLike()));
        criteria.setUsedCustomerIdLike(searchString(criteria.getUsedCustomerIdLike()));
        criteria.setUsedCustomerUidLike(searchString(criteria.getUsedCustomerUidLike()));
        criteria.setUsedCustomerNameLike(searchString(criteria.getUsedCustomerNameLike()));
        criteria.setUsedPhoneLike(searchString(criteria.getUsedPhoneLike()));
        criteria.setUserIdLike(searchString(criteria.getUserIdLike()));
        criteria.setUserUidLike(searchString(criteria.getUserUidLike()));
        criteria.setUserNameLike(searchString(criteria.getUserNameLike()));

        if(criteria.getRecordId() != null) {
            buf.append("    AND RECORD_ID = " + criteria.getRecordId());
        }
        if(criteria.getCouponUidEquals() != null) {
            buf.append("    AND COUPONUID = '" + criteria.getCouponUidEquals() + "'");
        }
        if(criteria.getCouponUidNotEquals() != null) {
            buf.append("    AND COUPONUID != '" + criteria.getCouponUidNotEquals() + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCouponManageUidEquals())) {
            buf.append("    AND COUPONMANAGEUID = '" + cut(criteria.getCouponManageUidEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCouponManageUidNotEquals())) {
            buf.append("    AND COUPONMANAGEUID != '" + cut(criteria.getCouponManageUidNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCouponManageUidLike())) {
            buf.append("    AND COUPONMANAGEUID LIKE '" + cut(criteria.getCouponManageUidLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberEquals())) {
            buf.append("    AND NUMBER = '" + cut(criteria.getNumberEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberNotEquals())) {
            buf.append("    AND NUMBER != '" + cut(criteria.getNumberNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberLike())) {
            buf.append("    AND NUMBER LIKE '" + cut(criteria.getNumberLike()) + "'");
        }
        if(criteria.getEndTimeUpper() != null) {
            buf.append("    AND ENDTIME <= " + criteria.getEndTimeUpper());
        }
        if(criteria.getEndTimeLower() != null) {
            buf.append("    AND ENDTIME >= " + criteria.getEndTimeLower());
        }
        if(criteria.getEndTimeEquals() != null) {
            buf.append("    AND ENDTIME = '" + criteria.getEndTimeEquals() + "'");
        }
        if(criteria.getEndTimeNotEquals() != null) {
            buf.append("    AND ENDTIME != '" + criteria.getEndTimeNotEquals() + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTypeEquals())) {
            buf.append("    AND TYPE = '" + cut(criteria.getTypeEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTypeNotEquals())) {
            buf.append("    AND TYPE != '" + cut(criteria.getTypeNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTypeLike())) {
            buf.append("    AND TYPE LIKE '" + cut(criteria.getTypeLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getModalityEquals())) {
            buf.append("    AND MODALITY = '" + cut(criteria.getModalityEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getModalityNotEquals())) {
            buf.append("    AND MODALITY != '" + cut(criteria.getModalityNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getModalityLike())) {
            buf.append("    AND MODALITY LIKE '" + cut(criteria.getModalityLike()) + "'");
        }
        if(criteria.getFullMoneyUpper() != null) {
            buf.append("    AND FULLMONEY <= " + criteria.getFullMoneyUpper());
        }
        if(criteria.getFullMoneyLower() != null) {
            buf.append("    AND FULLMONEY >= " + criteria.getFullMoneyLower());
        }
        if(criteria.getMinusMoneyUpper() != null) {
            buf.append("    AND MINUSMONEY <= " + criteria.getMinusMoneyUpper());
        }
        if(criteria.getMinusMoneyLower() != null) {
            buf.append("    AND MINUSMONEY >= " + criteria.getMinusMoneyLower());
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidEquals())) {
            buf.append("    AND SHOPUID = '" + cut(criteria.getShopUidEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidNotEquals())) {
            buf.append("    AND SHOPUID != '" + cut(criteria.getShopUidNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidLike())) {
            buf.append("    AND SHOPUID LIKE '" + cut(criteria.getShopUidLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameEquals())) {
            buf.append("    AND SHOPNAME = '" + cut(criteria.getShopNameEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameNotEquals())) {
            buf.append("    AND SHOPNAME != '" + cut(criteria.getShopNameNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameLike())) {
            buf.append("    AND SHOPNAME LIKE '" + cut(criteria.getShopNameLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksEquals())) {
            buf.append("    AND REMARKS = '" + cut(criteria.getRemarksEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksNotEquals())) {
            buf.append("    AND REMARKS != '" + cut(criteria.getRemarksNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksLike())) {
            buf.append("    AND REMARKS LIKE '" + cut(criteria.getRemarksLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getStateEquals())) {
            buf.append("    AND STATE = '" + cut(criteria.getStateEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getStateNotEquals())) {
            buf.append("    AND STATE != '" + cut(criteria.getStateNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getStateLike())) {
            buf.append("    AND STATE LIKE '" + cut(criteria.getStateLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getIdEquals())) {
            buf.append("    AND ID = '" + cut(criteria.getIdEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getIdNotEquals())) {
            buf.append("    AND ID != '" + cut(criteria.getIdNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getIdLike())) {
            buf.append("    AND ID LIKE '" + cut(criteria.getIdLike()) + "'");
        }
        if (criteria.getCreateTimeUpper() != null) {
            buf.append("    AND CREATETIME <= " + criteria.getCreateTimeUpper());
        }
        if (criteria.getCreateTimeLower() != null) {
            buf.append("    AND CREATETIME >= " + criteria.getCreateTimeLower());
        }
        if (criteria.getCreateTimeEquals() != null) {
            buf.append("    AND CREATETIME = '" + criteria.getCreateTimeEquals() + "'");
        }
        if (criteria.getCreateTimeNotEquals() != null) {
            buf.append("    AND CREATETIME != '" + criteria.getCreateTimeNotEquals() + "'");
        }
        if (criteria.getModifyTimeUpper() != null) {
            buf.append("    AND MODIFYTIME <= " + criteria.getModifyTimeUpper());
        }
        if (criteria.getModifyTimeLower() != null) {
            buf.append("    AND MODIFYTIME >= " + criteria.getModifyTimeLower());
        }
        if (criteria.getModifyTimeEquals() != null) {
            buf.append("    AND MODIFYTIME = '" + criteria.getModifyTimeEquals() + "'");
        }
        if (criteria.getModifyTimeNotEquals() != null) {
            buf.append("    AND MODIFYTIME != '" + criteria.getModifyTimeNotEquals() + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerIdEquals())) {
            buf.append("    AND CUSTOMERID = '" + cut(criteria.getCustomerIdEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerIdNotEquals())) {
            buf.append("    AND CUSTOMERID != '" + cut(criteria.getCustomerIdNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerIdLike())) {
            buf.append("    AND CUSTOMERID LIKE '" + cut(criteria.getCustomerIdLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerUidEquals())) {
            buf.append("    AND CUSTOMERUID = '" + cut(criteria.getCustomerUidEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerUidNotEquals())) {
            buf.append("    AND CUSTOMERUID != '" + cut(criteria.getCustomerUidNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerUidLike())) {
            buf.append("    AND CUSTOMERUID LIKE '" + cut(criteria.getCustomerUidLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerNameEquals())) {
            buf.append("    AND CUSTOMERNAME = '" + cut(criteria.getCustomerNameEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerNameNotEquals())) {
            buf.append("    AND CUSTOMERNAME != '" + cut(criteria.getCustomerNameNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerNameLike())) {
            buf.append("    AND CUSTOMERNAME LIKE '" + cut(criteria.getCustomerNameLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneEquals())) {
            buf.append("    AND PHONE = '" + cut(criteria.getPhoneEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneNotEquals())) {
            buf.append("    AND PHONE != '" + cut(criteria.getPhoneNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneLike())) {
            buf.append("    AND PHONE LIKE '" + cut(criteria.getPhoneLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUrlEquals())) {
            buf.append("    AND QRCODEURL = '" + cut(criteria.getQrCodeUrlEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUrlNotEquals())) {
            buf.append("    AND QRCODEURL != '" + cut(criteria.getQrCodeUrlNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUrlLike())) {
            buf.append("    AND QRCODEURL LIKE '" + cut(criteria.getQrCodeUrlLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUidEquals())) {
            buf.append("    AND QRCODEUID = '" + cut(criteria.getQrCodeUidEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUidNotEquals())) {
            buf.append("    AND QRCODEUID != '" + cut(criteria.getQrCodeUidNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUidLike())) {
            buf.append("    AND QRCODEUID LIKE '" + cut(criteria.getQrCodeUidLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCouponStateEquals())) {
            buf.append("    AND COUPONSTATE = '" + cut(criteria.getCouponStateEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCouponStateNotEquals())) {
            buf.append("    AND COUPONSTATE != '" + cut(criteria.getCouponStateNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCouponStateLike())) {
            buf.append("    AND COUPONSTATE LIKE '" + cut(criteria.getCouponStateLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerIdEquals())) {
            buf.append("    AND CURRENTCUSTOMERID = '" + cut(criteria.getCurrentCustomerIdEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerIdNotEquals())) {
            buf.append("    AND CURRENTCUSTOMERID != '" + cut(criteria.getCurrentCustomerIdNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerIdLike())) {
            buf.append("    AND CURRENTCUSTOMERID LIKE '" + cut(criteria.getCurrentCustomerIdLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerUidEquals())) {
            buf.append("    AND CURRENTCUSTOMERUID = '" + cut(criteria.getCurrentCustomerUidEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerUidNotEquals())) {
            buf.append("    AND CURRENTCUSTOMERUID != '" + cut(criteria.getCurrentCustomerUidNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerUidLike())) {
            buf.append("    AND CURRENTCUSTOMERUID LIKE '" + cut(criteria.getCurrentCustomerUidLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerNameEquals())) {
            buf.append("    AND CURRENTCUSTOMERNAME = '" + cut(criteria.getCurrentCustomerNameEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerNameNotEquals())) {
            buf.append("    AND CURRENTCUSTOMERNAME != '" + cut(criteria.getCurrentCustomerNameNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentCustomerNameLike())) {
            buf.append("    AND CURRENTCUSTOMERNAME LIKE '" + cut(criteria.getCurrentCustomerNameLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentPhoneEquals())) {
            buf.append("    AND CURRENTPHONE = '" + cut(criteria.getCurrentPhoneEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentPhoneNotEquals())) {
            buf.append("    AND CURRENTPHONE != '" + cut(criteria.getCurrentPhoneNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getCurrentPhoneLike())) {
            buf.append("    AND CURRENTPHONE LIKE '" + cut(criteria.getCurrentPhoneLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerIdEquals())) {
            buf.append("    AND USEDCUSTOMERID = '" + cut(criteria.getUsedCustomerIdEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerIdNotEquals())) {
            buf.append("    AND USEDCUSTOMERID != '" + cut(criteria.getUsedCustomerIdNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerIdLike())) {
            buf.append("    AND USEDCUSTOMERID LIKE '" + cut(criteria.getUsedCustomerIdLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerUidEquals())) {
            buf.append("    AND USEDCUSTOMERUID = '" + cut(criteria.getUsedCustomerUidEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerUidNotEquals())) {
            buf.append("    AND USEDCUSTOMERUID != '" + cut(criteria.getUsedCustomerUidNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerUidLike())) {
            buf.append("    AND USEDCUSTOMERUID LIKE '" + cut(criteria.getUsedCustomerUidLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerNameEquals())) {
            buf.append("    AND USEDCUSTOMERNAME = '" + cut(criteria.getUsedCustomerNameEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerNameNotEquals())) {
            buf.append("    AND USEDCUSTOMERNAME != '" + cut(criteria.getUsedCustomerNameNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedCustomerNameLike())) {
            buf.append("    AND USEDCUSTOMERNAME LIKE '" + cut(criteria.getUsedCustomerNameLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedPhoneEquals())) {
            buf.append("    AND USEDPHONE = '" + cut(criteria.getUsedPhoneEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedPhoneNotEquals())) {
            buf.append("    AND USEDPHONE != '" + cut(criteria.getUsedPhoneNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUsedPhoneLike())) {
            buf.append("    AND USEDPHONE LIKE '" + cut(criteria.getUsedPhoneLike()) + "'");
        }
        if(criteria.getUsedTimeUpper() != null) {
            buf.append("    AND USEDTIME <= " + criteria.getUsedTimeUpper());
        }
        if(criteria.getUsedTimeLower() != null) {
            buf.append("    AND USEDTIME >= " + criteria.getUsedTimeLower());
        }
        if(criteria.getUsedTimeEquals() != null) {
            buf.append("    AND USEDTIME = '" + criteria.getUsedTimeEquals() + "'");
        }
        if(criteria.getUsedTimeNotEquals() != null) {
            buf.append("    AND USEDTIME != '" + criteria.getUsedTimeNotEquals() + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserIdEquals())) {
            buf.append("    AND USERID = '" + cut(criteria.getUserIdEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserIdNotEquals())) {
            buf.append("    AND USERID != '" + cut(criteria.getUserIdNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserIdLike())) {
            buf.append("    AND USERID LIKE '" + cut(criteria.getUserIdLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserUidEquals())) {
            buf.append("    AND USERUID = '" + cut(criteria.getUserUidEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserUidNotEquals())) {
            buf.append("    AND USERUID != '" + cut(criteria.getUserUidNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserUidLike())) {
            buf.append("    AND USERUID LIKE '" + cut(criteria.getUserUidLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserNameEquals())) {
            buf.append("    AND USERNAME = '" + cut(criteria.getUserNameEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserNameNotEquals())) {
            buf.append("    AND USERNAME != '" + cut(criteria.getUserNameNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getUserNameLike())) {
            buf.append("    AND USERNAME LIKE '" + cut(criteria.getUserNameLike()) + "'");
        }
        if(sort != null && sort.getColumns().size() > 0) {
            buf.append(" ORDER BY ");
            sort.getColumns().forEach(c->buf.append(c.getColumnName().toUpperCase())
                .append(" ").append((c.getAscending() != null && c.getAscending()) ? "ASC" : "DESC")
                .append(", "));
            buf.append("RECORD_ID ASC");
        }
        return buf.toString();
    }

    @Override
    public <T extends Unit > String getUpdateStatement(T source) {
        CouponListBean data = null;

        if(source instanceof com.restaurant.application.indexes.couponlist.mysql.CouponListFromcouponUidIF) {
            data = new CouponListBean();
             ((com.restaurant.application.indexes.couponlist.mysql.CouponListFromcouponUidIF)source).getCouponUidDataForCouponList(data);
        }

        return data == null ? null: getLocalUpdateStatement(data);
    }
}
